package stack

import "fmt"

type SqStack struct {
	elem []int
}

func NewSqStack() *SqStack {
	return &SqStack{
		elem: make([]int, 0),
	}
}

func (sq *SqStack) AddNode(v int) {
	sq.elem = append(sq.elem, v)

	fmt.Println("now sq len:", len(sq.elem))
}

func (sq *SqStack) DelNode() int {
	if len(sq.elem) == 0 {
		return -1
	}

	if len(sq.elem) == 1 {
		value := sq.elem[0]
		sq.elem = make([]int, 0)
		return value
	}

	value := sq.elem[len(sq.elem) -1]
	sq.elem = sq.elem[0: len(sq.elem) -1]
	return value
}

func (sq *SqStack) Print() {
	if sq.elem == nil {
		return
	}

	for _, v :=range  sq.elem {
		fmt.Printf(" %d", v)
	}
	fmt.Println()
}